﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using NUnit.Framework;

using ReferenceSwap;

namespace ReferenceSwap.Tests
{
    [TestFixture]
    public class ProjectDataFixture
    {
        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyNullStringCheck()
        {
            new ProjectData(null);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void VerifyEmptyStringCheck()
        {
            new ProjectData("");
        }

        [Test]
        [ExpectedException(typeof(FileNotFoundException))]
        public void VerifyInvalidPathCheck()
        {
            new ProjectData(@"c:\test.csproj");
        }

        [Test]
        public void TestParseOutput()
        {
            string expected = "ReferenceSwap.Example";
            var target = new ProjectData(TestData.ProjectFile);
            Assert.AreEqual(expected, target.Output);
        }

        [Test]
        public void TestParseAssemblyReferences_IgnoreSystem()
        {
            int expected = 1;
            var target = new ProjectData(TestData.ProjectFile, true);
            Assert.AreEqual(expected, target.AssemblyReferences.Count);
        }

        [Test]
        public void TestParseAssemblyReferences_DoNotIgnoreSystem()
        {
            int expected = 8;
            var target = new ProjectData(TestData.ProjectFile, false);
            Assert.AreEqual(expected, target.AssemblyReferences.Count);
        }

        [Test]
        public void TestParseProjectReferences()
        {
            int expectedCount = 3;
            var target = new ProjectData(TestData.ProjectFile);
            Assert.AreEqual(expectedCount, target.ProjectReferences.Count);
        }

        [Test]
        public void TestRemoveProjectReference()
        {
            var target = new ProjectData(TestData.ProjectFile);
            target.RemoveProjectReference(target.ProjectReferences[0]);

            Assert.AreEqual(2, target.ProjectReferences.Count);
        }

        [Test]
        public void TestFindSolution()
        {
            string expectedSolution = "ReferenceSwap.sln";
            var target = new ProjectData(TestData.ProjectFile);
            var solution = target.FindSolution();

            Assert.IsNotNull(solution);
            Assert.IsTrue(solution.SolutionFile.FullName.Contains(expectedSolution));
        }

    }
}
